package com.sugar.junit.test.tree;

import java.io.File;
import java.util.List;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;

public class LoadTree {
	
	static String str = "D:/Workspaces/MyEclipse8.5/Project/sugar/WebRoot/xml_tree/tree7.xml" ;
	static String str1 = "D:/Workspaces/MyEclipse8.5/Project/sugar/WebRoot/xml_tree/funcbar7.xml" ;

	public static void main(String[] args) throws Exception {
		inits() ;
	}
	
	public static  void inits() throws Exception {
		SAXBuilder sb = new SAXBuilder() ;
		Document doc = sb.build(new File(str)) ;
		Element root = doc.getRootElement() ;
		
		Document func = sb.build(new File(str1)) ;
		Element funcElt = func.getRootElement() ;
		
		System.out.println(root.getAttributeValue("text"));
		System.out.println(root.getAttributeValue("joint"));
		
		loadsTree(root,funcElt) ;
	}
	
	public static void loadsTree(Element root,Element joint) throws Exception {
		
		
		List<?> childs = root.getChildren() ;
		
		if(null != childs && childs.size() > 0) {
			for(int i=0; i<childs.size(); i++) {
				Element e1 = (Element) childs.get(i) ;
				if(e1.getAttributeValue("text") != null) {
					System.out.println(e1.getAttributeValue("text") + "=" + e1.getAttributeValue("parent") + "=" + e1.getAttributeValue("child"));
					
					if(e1.getChildText("userdata") != null) {
						System.out.println("\t"+e1.getChildText("userdata"));
						System.out.println("");
					}
					
					if(null != e1.getChildren() && e1.getChildren().size() > 0) {
						//loadsTree(e1) ;
					}
				}
			}
			
		}
		
		
		
		
	}
	
}
